package com.googlecode.beanfiles;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@SuppressWarnings("unchecked")
public class ListPropertiedBean {

    private List strings;
    private List integers;

    protected static Log log() {
        return LogFactory.getLog(ListPropertiedBean.class);
    }

    public ListPropertiedBean() {}

    public List getStrings() {
        return strings;
    }

    public void setStrings(List strings) {
        this.strings = strings;
    }

    public List getIntegers() {
        return integers;
    }

    public void setIntegers(List integers) {
        this.integers = integers;
    }

    public boolean equals(Object o) {
        if (!(o instanceof ListPropertiedBean)) {
            return false;
        }
        ListPropertiedBean bean = (ListPropertiedBean) o;
        if (oneIsNull(bean.getStrings(), getStrings()) ||
                (neitherIsNull(bean.getStrings(), getStrings()) && (!bean.getStrings().equals(
                    getStrings())))) {
            return false;
        } else if (oneIsNull(bean.getIntegers(), getIntegers()) ||
                (neitherIsNull(bean.getIntegers(), getIntegers()) && (!bean.getIntegers().equals(
                    getIntegers())))) {
            return false;
        }
        return true;
    }

    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("[strings: " + getStrings() + "]");
        builder.append("[integer: " + getIntegers() + "]");
        return builder.toString();
    }

    private boolean oneIsNull(List<?> list1, List<?> list2) {
        return (list1 == null && list2 != null) || (list2 == null && list1 != null);
    }

    private boolean neitherIsNull(List<?> list1, List<?> list2) {
        return list1 != null && list2 != null;
    }

}
